<?php
/**
 * Created by PhpStorm.
 * User: lingyun
 * Date: 2018/3/1
 * Time: 13:44
 * Desc: 官网底部文章
 */
namespace app\index\controller;
use think\Controller;
use think\Db;
use app\index\controller\Base;

class Article extends Base{
    /**
     * @Author  lingyun
     * @Desc    系统文章
     */
    public function index(){
        $realname = db('user')->where('uid',session('_user_uid_.uid'))->value('realname');
        $cate_id = input('cate_id');
        $store = db('store')->where('id',cookie('store_id'))->find();
        $info = db('article')->where('cate_id',$cate_id)->find();
        $info['content'] = htmlspecialchars_decode($info['content']);
        $this->get_header();
        $this->get_user_info();



        $this->assign('realname',$realname);
        $this->assign('cate_id',$cate_id);
        $this->assign('info',$info);
        $this->assign('store',$store);
        return $this->fetch('index');
    }

    /**
     * @Author  lingyun
     * @Desc    获取头部信息
     */
    public function get_header(){
//        $sql = "SELECT id,name,logo,cat_id FROM ys_goods AS a WHERE 5> (SELECT COUNT(*) FROM ys_goods WHERE cat_id=a.cat_id AND id>a.id) AND a.is_online=1 AND a.status=1 AND a.is_deleted=0 ORDER BY a.id DESC";
        $sql = "SELECT id,name,logo,cat_id FROM ys_goods AS a WHERE 6> (SELECT COUNT(*) FROM ys_goods WHERE cat_id=a.cat_id AND id>a.id) AND a.is_online=1 AND a.status=1 AND a.is_deleted=0 AND is_top>0 ORDER BY a.id DESC";
        $tui_goods = Db::query($sql);

        $category = get_top_category();           //商品顶级分类
        $exp_category = get_exp_category();       //商品扩展分类
        $this->assign('tui_goods',$tui_goods);
        $this->assign('category',$category);
        $this->assign('exp_category',$exp_category);

    }

    /**
     * @Author  lingyun
     * @Desc    获取会员信息
     */
    public function get_user_info(){
        $uid = session('_user_uid_.uid');
        $user = Db::name('user')->where('uid',$uid)->find();        //会员信息
        $store = db('store')->where('id',cookie('store_id'))->find();
//        $level_info = get_user_level($user['level_point']);         //会员的等级信息
        $level_info = get_user_level($user['level_id']);         //会员的等级信息
        $user['mobile'] = substr_replace($user['mobile'],'****',3,4);

        $this->assign('user',$user);                    //会员信息
        $this->assign('store',$store);                    //会员信息
        $this->assign('level_info',$level_info);        //会员等级信息
    }


}